$(function () {
    // 普通文件管理
    $('#generalFileManager').kendoFileManager({
        dataSource: {
            transport: {
                create: function (options) {
                    $.fn.ajaxPost({
                        ajaxData: options.data,
                        ajaxUrl: 'json/response.json',
                        succeed: function (res) {
                            options.success(res);
                        },
                        failed: function (res) {
                            options.error(res);
                        }
                    });
                },
                destroy: function (options) {
                    $.fn.ajaxPost({
                        ajaxData: options.data,
                        ajaxUrl: 'json/response.json',
                        succeed: function (res) {
                            options.success(res);
                        },
                        failed: function (res) {
                            options.error(res);
                        }
                    });
                },
                update: function (options) {
                    $.fn.ajaxPost({
                        ajaxData: options.data,
                        ajaxUrl: 'json/response.json',
                        succeed: function (res) {
                            options.success(res);
                        },
                        failed: function (res) {
                            options.error(res);
                        }
                    });
                },
                read: function (options) {
                    $.fn.ajaxPost({
                        ajaxData: options.data,
                        ajaxUrl: 'json/filemanager.json',
                        succeed: function (res) {
                            var key = options.data.path;
                            if (key) {
                                options.success(res[key.split('/')[key.split('/').length - 1]]);
                            } else {
                                options.success(res.root);
                            }
                        },
                        failed: function (res) {
                            var key = options.data.path;
                            if (key) {
                                options.error(res[key.split('/')[key.split('/').length - 1]]);
                            } else {
                                options.error(res.root);
                            }
                        }
                    });
                }
            },
            schema: {
                model: {
                    id: 'path',
                    hasChildren: 'hasDirectories',
                    fields: {
                        name: { type: 'string',
                            editable: true,
                            defaultValue: 'New Folder'
                        },
                        extension: { type: 'string',
                            editable: false
                        },
                        size: { type: 'number',
                            editable: false
                        },
                        path: { type: 'string',
                            editable: false
                        },
                        isDirectory: { type: 'boolean',
                            editable: false,
                            defaultValue: true
                        },
                        hasDirectories: { type: 'boolean',
                            editable: false,
                            defaultValue: false
                        },
                        created: { type: 'date',
                            editable: false
                        },
                        createdUtc: { type: 'date',
                            editable: false
                        },
                        modified: { type: 'date',
                            editable: false
                        },
                        modifiedUtc: { type: 'date',
                            editable: false
                        }
                    }
                }
            }
        },
        uploadUrl: 'json/upload.json'
    });
});